<template>
  <div class="ma-content-block">
    <sa-table ref="crudRef" :options="options" :columns="columns" :searchForm="searchForm">
      <!-- 搜索区 tableSearch -->
      <template #tableSearch>
        <a-col :span="8">
          <a-form-item label="姓名" field="name">
            <a-input v-model="searchForm.name" placeholder="请输入姓名" />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="性别" field="gender">
            <a-input v-model="searchForm.gender" placeholder="请输入性别" />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="联系电话" field="contact_number">
            <a-input v-model="searchForm.contact_number" placeholder="请输入联系电话" />
          </a-form-item>
        </a-col>
<!--        <a-col :span="8">-->
<!--          <a-form-item label="籍贯" field="domicile">-->
<!--            <a-input v-model="searchForm.domicile" placeholder="请输入籍贯" />-->
<!--          </a-form-item>-->
<!--        </a-col>-->
<!--        <a-col :span="8">-->
<!--          <a-form-item label="现在居住地" field="current_residence">-->
<!--            <a-input v-model="searchForm.current_residence" placeholder="请输入现在居住地" />-->
<!--          </a-form-item>-->
<!--        </a-col>-->
<!--        <a-col :span="8">-->
<!--          <a-form-item label="学历" field="education_level">-->
<!--            <a-input v-model="searchForm.education_level" placeholder="请输入学历" />-->
<!--          </a-form-item>-->
<!--        </a-col>-->
<!--        <a-col :span="8">-->
<!--          <a-form-item label="英语水平" field="english_level">-->
<!--            <a-input v-model="searchForm.english_level" placeholder="请输入英语水平" />-->
<!--          </a-form-item>-->
<!--        </a-col>-->
<!--        <a-col :span="8">-->
<!--          <a-form-item label="更新时间" field="update_time">-->
<!--            <a-input v-model="searchForm.update_time" placeholder="请输入更新时间" />-->
<!--          </a-form-item>-->
<!--        </a-col>-->
      </template>
      <template #operationBeforeExtend="{ record }">
        <a-link @click="openDetail(record)"   v-auth="['/talent/talent/detail']"> <icon-plus /> 查看 </a-link>
      </template>
      <!-- Table 自定义渲染 -->
    </sa-table>

    <!-- 编辑表单 -->
    <edit-form ref="editRef" @success="refresh" />
    <detail-form ref="detailRef" @success="refresh" />
  </div>
</template>

<script setup>
import { onMounted, ref, reactive } from 'vue'
import { Message } from '@arco-design/web-vue'
import EditForm from './edit.vue'
import detailForm from './detail.vue'
import api from '../api/talent'
import commonApi from '@/api/common'

// 引用定义
const crudRef = ref()
const editRef = ref()
const detailRef = ref()
// 搜索表单
const searchForm = ref({
  name: '',
  gender: '',
  contact_number: '',
  domicile: '',
  current_residence: '',
  education_level: '',
  english_level: '',
  update_time: '',
})


// SaTable 基础配置
const options = reactive({
  api: api.getPageList,
  pk: 'talent_id',
  rowSelection: { showCheckedAll: true },
  // add: {
  //   show: true,
  //   auth: ['/talent/talent/save'],
  //   func: async () => {
  //     editRef.value?.open()
  //   },
  // },
  // edit: {
  //   show: true,
  //   auth: ['/talent/talent/update'],
  //   func: async (record) => {
  //     editRef.value?.open('edit')
  //     editRef.value?.setFormData(record)
  //   },
  // },
  delete: {
    show: true,
    auth: ['/talent/talent/destroy'],
    func: async (params) => {
      const resp = await api.delete(params)
      if (resp.code === 200) {
        Message.success(`删除成功！`)
        crudRef.value?.refresh()
      }
    },
  },
  export: { show: true, url: '/talent/talent/export', auth: ['/talent/talent/export'] },
})

// SaTable 列配置
const columns = reactive([
  { title: '姓名', dataIndex: 'name', width: 180 },
  { title: '性别', dataIndex: 'gender',dict: 'sex', width: 180 },
  { title: '联系电话', dataIndex: 'contact_number', width: 180 },
  { title: '出生年月', dataIndex: 'birth_date', width: 180 },
  { title: '籍贯', dataIndex: 'domicile', width: 180 },
  { title: '现在居住地', dataIndex: 'current_residence', width: 180 },
  { title: '学历', dataIndex: 'education_level', width: 180 },
  { title: '毕业学校', dataIndex: 'graduation_school', width: 180 },
  { title: '英语水平', dataIndex: 'english_level', width: 180 },
  { title: '求职意向', dataIndex: 'career_intention', width: 180 },
  { title: '更新时间', dataIndex: 'update_time', width: 180 },
])

// 页面数据初始化
const initPage = async () => {}

// 查看详情
const openDetail = (record) => {
  detailRef.value?.open()
  detailRef.value?.setFormData(record)
}


// SaTable 数据请求
const refresh = async () => {
  crudRef.value?.refresh()
}

// 页面加载完成执行
onMounted(async () => {
  initPage()
  refresh()
})
</script>
